package com.mo.ld.activity.interactive

import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mo.ld.R
import com.mo.ld.bean.ActionBean
import com.mo.ld.modle.getMainAdapter2
import com.mo.lib.ui.activity.BaseRvActivity
import com.mo.lib.ui.dialog.BaseDialog
import com.mo.lib.utils.KLog
import com.mo.lib.utils.setClick
import com.mo.lib.utils.time.KCountDownTimer
import com.mo.lib.utils.time.TimerHelper
import java.util.*

/**
 * @ author：mo
 * @ data：2022/4/26:9:33
 * @ 功能：时间相关
 */
class TimeAboutActivity : BaseRvActivity<ActionBean>() {
    var timer: Timer? = null
    val timerHelper: TimerHelper = TimerHelper()
    override fun initData() {
    }

    override fun creatAdaper(): BaseQuickAdapter<ActionBean, BaseViewHolder> {
        return getMainAdapter2(mutableListOf(ActionBean("定时器") {

            timerHelper.start(0, 2000) {
                KLog.i(com.xuexiang.xutil.data.DateUtils.getNowDate().toString())
            }
        }, ActionBean("弹窗倒计时") {
            object : BaseDialog(R.layout.item_main) {
                override fun doWhat() {
                    val tv_item_main = dialog.findViewById<TextView>(R.id.tv_item_main)
                    val value = object : KCountDownTimer(3000, 1000) {
                        override fun onTicks(millisUntilFinished: Long, second: Int) {
                            tv_item_main.text = "还剩${second} 秒"
                            KLog.i(com.xuexiang.xutil.data.DateUtils.getNowDate().toString())
                        }

                        override fun onFinish() {
                            super.onFinish()
                            tv_item_main.text = "重新开始"
                        }
                    }
                    tv_item_main.setClick {
                        KLog.i("DDDDDDDDD")
                        value.start()
                    }

                }
            }.show()
        })).also {
            it.setOnItemClickListener(object : OnItemClickListener {
                override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
                    timerHelper.stop()
                }
            })
        }
    }

    override fun onPause() {
        super.onPause()
        timerHelper.stop()
    }

    override fun getList(page: Int) {
    }

    override fun getMore(page: Int) {
    }
}
